﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace InfoPick.Lib.Service
{
    public class PathService
    {
        private static readonly string mgwContainer = "MGWPath";
        private static readonly string mscContainer = "MSCPath";
        private static readonly string excelContainer = "ExcelPath";

        public string GetMGWPath()
        {
            XDocument xdoc = XDocument.Load(Global.XmlDataPath);

            var ele = xdoc.Root.Element(mgwContainer);
            if (ele != null)
                return ele.Attribute("Last").Value;
            return string.Empty;
        }

        public string GetMSCPath()
        {
            XDocument xdoc = XDocument.Load(Global.XmlDataPath);

            var ele = xdoc.Root.Element(mscContainer);
            if (ele != null)
                return ele.Attribute("Last").Value;
            return string.Empty;
        }

        public string GetLastExcelPath()
        {
            XDocument xdoc = XDocument.Load(Global.XmlDataPath);

            var ele = xdoc.Root.Element(excelContainer);
            if (ele != null)
                return ele.Attribute("Last").Value;
            return string.Empty;
        }

        public void SetMGWPath(string path)
        {
            XDocument xdoc = XDocument.Load(Global.XmlDataPath);

            var ele = xdoc.Root.Element(mgwContainer);
            ele.SetAttributeValue("Last", path);
            xdoc.Save(Global.XmlDataPath);
        }

        public void SetMSCPath(string path)
        {
            XDocument xdoc = XDocument.Load(Global.XmlDataPath);

            var ele = xdoc.Root.Element(mscContainer);
            ele.SetAttributeValue("Last", path);
            xdoc.Save(Global.XmlDataPath);
        }

        public void SetExcelPath(string path)
        {
            XDocument xdoc = XDocument.Load(Global.XmlDataPath);

            var ele = xdoc.Root.Element(excelContainer);
            ele.SetAttributeValue("Last", path);
            xdoc.Save(Global.XmlDataPath);
        }
    }
}
